﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace PointTracker
{
    public partial class _Default : System.Web.UI.Page
    {
        public List<Class> classes;

        protected void Page_Load(object sender, EventArgs e)
        {
            Session.Clear();

            //GetClasses2("as566@drexel.edu");    // for now... dun dun dun
        }

        public void GetClasses2(string userEmail)
        {
            /*List<Class> */
            classes = PointTracker.Class.getClasses(userEmail);

            if (classes.Count() > 0)
            {

                Table table = new Table();
                table.ID = "classTable";
                Page.Form.Controls.Add(table);

                TableRow headerRow = new TableRow();

                TableHeaderCell hCellName = new TableHeaderCell();
                hCellName.Text = "Class name";
                hCellName.Width = 100;
                hCellName.Style.Add("font-weight", "bold");
                TableHeaderCell hCellTerm = new TableHeaderCell();
                hCellTerm.Text = "Term";
                hCellTerm.Width = 100;
                hCellTerm.Style.Add("font-weight", "bold");
                TableHeaderCell hCellYear = new TableHeaderCell();
                hCellYear.Text = "Year";
                hCellYear.Width = 50;
                hCellYear.Style.Add("font-weight", "bold");

                headerRow.Cells.Add(hCellName);
                headerRow.Cells.Add(hCellTerm);
                headerRow.Cells.Add(hCellYear);

                table.Controls.Add(headerRow);

                foreach (Class singleClass in classes)
                {
                    TableRow tempRow = new TableRow();

                    TableCell tempCellName = new TableCell();
                    tempCellName.Text = "<a href='/viewEditPoints.aspx?class=" + singleClass.crn + "' >" + singleClass.name + "</a>";
                    TableCell tempCellTerm = new TableCell();
                    tempCellTerm.Text = singleClass.term.ToString();
                    TableCell tempCellYear = new TableCell();
                    tempCellYear.Text = singleClass.year.ToString();

                    tempRow.Cells.Add(tempCellName);
                    tempRow.Cells.Add(tempCellTerm);
                    tempRow.Cells.Add(tempCellYear);

                    table.Controls.Add(tempRow);
                }

                divClasses.Controls.Add(table);
            }
        }
    }
}
